package com.neusoft.neuiotms.dcom.repository.incident.impl;

import com.neusoft.bizcore.web.jpa.repository.AbstractRepository;
import com.neusoft.neuiotms.dcom.model.incident.IncidentRegister;
import com.neusoft.neuiotms.dcom.model.incident.QIncidentRegister;
import com.neusoft.neuiotms.dcom.repository.incident.CustomizedIncidentRegisterRepository;
import com.querydsl.jpa.impl.JPAQuery;

/**
 * @author WYS
 * @date 2020年8月18日 下午2:10:01
 */
public class CustomizedIncidentRegisterRepositoryImpl extends AbstractRepository
        implements CustomizedIncidentRegisterRepository {

    @Override
    protected Class<?> getModelClass() {
        return IncidentRegister.class;
    }

    @Override
    public IncidentRegister findByWorkNum(final String workOrderNumber) {
        final QIncidentRegister qIncidentRegister = QIncidentRegister.incidentRegister;
        final JPAQuery<IncidentRegister> query = this.query().selectFrom(qIncidentRegister);
        query.where(qIncidentRegister.workNum.eq(workOrderNumber)).orderBy(qIncidentRegister.createTime.desc())
                .limit(1);
        return query.fetchOne();
    }

}
